#include <vector>
#include "Sqlite.hpp"
#include <cassert>

int Sqlite_Callback(void* arg,int col_count,char** result,char** fileds_name)
{
    std::vector<std::string>* array = (std::vector<std::string>*)arg;
    array->push_back(result[0]);
    return 0;
}

int main()
{
    SqliteHelper helper("./test.db");
    // 1.创建/打开库文件
    assert(helper.open());
    // 2.创建表(不存在则创建)， 学生信息 ： 学号，姓名，年龄
    // const char* ct = "create table if not exists students(sn int primary key auto_increase,name varchar(32), age int);";
    // 疑似不支持自增长。
    const char* ct = "create table if not exists student(sn int primary key,name varchar(32), age int);";
    assert(helper.exec(ct,nullptr,nullptr));
    // 3.新增数据  ，修改 ， 删除 ，查询
    const char* insert_sql = "insert into student values(1,'小明',18),(2,'小黑',19);";
    assert(helper.exec(insert_sql,nullptr,nullptr));

    // const char* update_sql = "update student set name = '小十三' where sn = 1;";
    // assert(helper.exec(update_sql,nullptr,nullptr));

    // const char* delete_sql = "delete from student where sn = 1;";
    // assert(helper.exec(delete_sql,nullptr,nullptr));

    const char* select_sql = "select name from student;";
    std::vector<std::string> array;
    assert(helper.exec(select_sql,Sqlite_Callback,&array));

    for(auto& e : array)
    {
        std::cout << e << std::endl;
    }

    // 4.关闭数据库
    helper.close();

    return 0;
}
